from random import randrange

import numpy as np
import pandas as pd
from flask import Flask, render_template
from flask.json import jsonify

from data import bar_base, map_base, line_set, funnel_set, map_set
# app = Flask(__name__, static_folder="templates")
from pyecharts_学习.data import line_base

app = Flask(__name__)
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True


@app.route("/")
def index():
    return render_template("index.html")


@app.route("/funnel")
def funnel():
    df = pd.DataFrame(np.zeros([2, 2]), columns=list('ab'))
    df['a'] = 1
    return render_template("funnel.html", df=df)


@app.route("/table_a")
def table_a():
    file_path = r'F:\SynologyDrive\SynologyDrive\git\项目2\能源\结果.xlsx'
    data = pd.read_excel(file_path)
    return render_template('table_a.html', data=data)


@app.route("/mabBase")
def get_map_base():
    c = map_base()
    return c.dump_options_with_quotes()


@app.route("/myfunnel")
def get_funnel_base():
    c = funnel_set()
    return c.dump_options_with_quotes()


@app.route("/mymap")
def get_map_data():
    c = map_set()
    return c.dump_options_with_quotes()


@app.route("/barChart")
def get_bar_chart():
    c = bar_base()
    return c.dump_options_with_quotes()


@app.route("/lineAreastyle")
def get_line_areastyle():
    c = line_set()
    return c.dump_options_with_quotes()


@app.route("/lineChart_add")
def get_line_chart_add():
    c = line_base()
    return c.dump_options_with_quotes()


idx = 9


@app.route("/lineDynamicData")
def update_line_data():
    global idx
    idx = idx + 1
    return jsonify({"name": idx, "value": randrange(50, 80)})


if __name__ == "__main__":
    app.run(debug=True)
